package br.pucrio.inf.csm;

import java.util.ArrayList;
import java.util.List;

// TODO: Isso pode ser um Composite de Match ??
// isso aqui antes era acesso default, validar depois...
public class CompositeMatch implements IMatch {

	private List<IMatch> matches = new ArrayList<IMatch>();

	public CompositeMatch() {
	}

	public CompositeMatch(IMatch... matchList) {
		for (IMatch match : matchList) {
			// TODO: VALIDAR
			matches.add(match);
		}
	}

	public void addMatch(IMatch... matchList) {
		for (IMatch match : matchList) {
			// TODO: VALIDAR
			matches.add(match);
		}
	}

	public void print() {
		if (matches.isEmpty()) {
			{
				System.out.println("there are no matches");
			}

		}
		for (IMatch match : matches) {
			match.print();
		}
	}

	public Object getMatch(Object element) throws MatchException {
		for (IMatch match : matches) {
			Object obj = match.getMatch(element);
			if (obj != null) {
				return obj;
			}
		}
		throw new MatchException("element not found!");
	}
}
